# This is a sample Python script.

# Press Shift+F10 to execute it or replace it with your code.
# Press Double Shift to search everywhere for classes, files, tool windows, actions, and settings.

# 读取文件夹中的文件，逐行解析
import os
import pprint
import time

import numpy as np

# 加载并读取config.json配置文件中的配置项
from gradio_client import Client, handle_file

from my_audio_client import MyAudioClient


def single_block(block_index, blocks=None, use_moji=True):
    # Use a breakpoint in the code line below to debug your script.
    print(f'Hi, {block_index}')  # Press Ctrl+F8 to toggle the breakpoint.
    my_audio_client = MyAudioClient()
    config = my_audio_client.load_config()

    if blocks is None:
        start_time = time.time()  # 开始时间
        lines = my_audio_client.read_file()
        rows = my_audio_client.parse_data(lines)
        blocks = my_audio_client.get_blocks(rows)
        duration_time = time.time() - start_time  # 切分块的时间
        print(f"切分块的时间：{duration_time} 秒")
    audio_path = my_audio_client.audio_path
    if not os.path.exists(audio_path):
        os.makedirs(audio_path)
    print(f"文件夹 {audio_path} 已创建")

    client = Client(config['gradio_url'])
    # pprint.pp(blocks[block_index])
    my_audio_client.geneAudio(blocks[block_index], block_index, client, use_moji=use_moji)

    print(block_index, len(blocks), blocks[block_index])





# Press the green button in the gutter to run the script.
if __name__ == '__main__':
    block_index = 8
    single_block(block_index)

# See PyCharm help at https://www.jetbrains.com/help/pycharm/
